// (c) 2005 Wout de Zeeuw

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;

namespace CaveArt.UIcomp
{
	public class StatusBarItem : Panel {
		private Control control;
		// Total width is the absolute + relative portion.
		private int absoluteWidth;
		private float relativeWidth;
	    private const int borderwidth = 2;
	    private static readonly Pen borderPen = new Pen(SystemColors.ControlDark);
		
		/// <summary>
		/// Constructor.
		/// </summary>
		public StatusBarItem(Control control, int absoluteWidth, float relativeWidth) {
			Dock = DockStyle.None;
			SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			SetStyle(ControlStyles.UserPaint, true);
			SetStyle(ControlStyles.ResizeRedraw, true);

			Panel panel = new Panel();
			panel.Dock = DockStyle.None;
			panel.BackColor = SystemColors.Control;
			BackColor = SystemColors.Control;
			panel.Bounds = 
				new Rectangle(
					borderwidth + 1,
					borderwidth + 1,
					Width - borderwidth * 2 - 2,
					Height - borderwidth * 2 - 2);
			panel.Anchor = 
				AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
			Controls.Add(panel);
			if (control != null) {
				panel.Controls.Add(control);
				control.Dock = DockStyle.Fill;
			}
			this.control = control;
			this.absoluteWidth = absoluteWidth;
			this.relativeWidth = relativeWidth;
		}
		
		/// <summary>
		/// The absolute portion of the total width.
		/// </summary>
		public int AbsoluteWidth {
			get {
				return absoluteWidth;
			}
		}

		/// <summary>
		/// The relative portion of the total width (0 - 1).
		/// </summary>
		public float RelativeWidth {
			get {
				return relativeWidth;
			}
		}
		
		/// <summary>
		/// Paints the border.
		/// </summary>
		protected override void OnPaint(PaintEventArgs e) {
			e.Graphics.DrawRectangle(
				borderPen, 
				borderwidth, 
				borderwidth, 
				Width - borderwidth * 2, 
				Height - borderwidth * 2);
		}
	}
}
